<template>
  <div>
    <a-form-model
      ref="ruleForm"
      :model="formData"
      :rules="rules"
    >
      <a-row>
        <a-col>
          <a-form-model-item
            label="公司简介"
            prop="introduction"
          >
            <BaseTextarea
              v-model="formData.introduction"
              :disabled="state === 3"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="资质证书"
            prop="certs"
          >
            <a-checkbox-group
              v-model="formData.certs"
              :disabled="state === 3"
            >
              <a-checkbox
                v-for="item in certificateArr"
                :key="item.id"
                :value="item.id"
              >
                {{ item.name }}
              </a-checkbox>
            </a-checkbox-group>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col span="12">
          <a-form-model-item
            label="纳税人类型"
            prop="taxpayerType"
          >
            <a-radio-group
              v-model="formData.taxpayerType"
              :disabled="state === 3"
            >
              <a-radio
                v-for="item in typeArr"
                :key="item.id"
                :value="item.id"
              >
                {{ item.name }}
              </a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col span="12">
          <a-form-model-item
            label="适用税率%"
            prop="taxRateType"
          >
            <b-input
              v-model="formData.taxRateType"
              :disabled="state === 3"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="产品特色"
            prop="featureOfProduct"
          >
            <BaseTextarea
              v-model="formData.featureOfProduct"
              :disabled="state === 3"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="供货能力"
            prop="supplyCapacity"
          >
            <BaseTextarea
              v-model="formData.supplyCapacity"
              :disabled="state === 3"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item label="企业业绩">
            <performance
              :id="row ? row.id : null"
              :state="state"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="售后服务"
            prop="saleService"
          >
            <BaseTextarea
              v-model="formData.saleService"
              :disabled="state === 3"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="现场考察照片"
            prop="fileInfo"
          >
            <l-table
              :upload-arrys.sync="formData.fileInfo"
              business-code="MM16"
              upload-type="image"
              count="12"
              edit-model="2"
              :disabled="state===3"
              @fileArrysData="fileArrysData"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="考察结论"
            prop="result"
          >
            <BaseTextarea
              v-model="formData.result"
              :auto-size="{ minRows: 3, maxRows: 5 }"
              :disabled="state === 3"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>
<script>
import { selectOption } from '@/api/material/goods/goods'
import { contentEidt } from '@/api/material/supplier/inspection'
import { supplierLabel } from '@/api/material/public/public'
import performance from '../performance/performance'
import { uploadFile } from '@/api'

export default {
	name:'a'+Date.now(),
    components: {
        performance,
    },
    props: {
        state: {
            type: Number
        },
        row: {
            type: Object
        }
    },
    data() {
        return {
            isSubmit: false,
            formData: {
                introduction: '',
                taxpayerType: 'COMMONLY',
                taxpayerTypeCode: 'COMMONLY',
                taxRateType: null,
                featureOfProduct: '',
                supplyCapacity: '',
                saleService: '',
                result: '',
                fileInfo: [],
                certs: []
            },
            rules: {
                introduction: { required: true, message: '公司简介不能为空', trigger: 'blur' },
                certs: { required: true, message: '资质证书不能为空', trigger: 'blur' },
                taxpayerType: { required: true, message: '纳税人类型不能为空', trigger: 'change' },
                taxRateType: { required: true, message: '适用税率不能为空', trigger: 'change' },
                featureOfProduct: { required: true, message: '产品特色不能为空', trigger: 'blur' },
                supplyCapacity: { required: true, message: '供货能力不能为空', trigger: 'blur' },
                fileInfo: { required: true, message: '现场考察照片不能为空', trigger: 'blur' },
                result: { required: true, message: '考察结论不能为空', trigger: 'change' },
                saleService: { required: true, message: '售后服务不能为空', trigger: 'change' }
            },
            certificateArr: [],
            typeArr: []
        }
    },
    mounted: async function() {
        await this.getType()
        this.getCertificate()
        this.formData = { ...this.formData, ...this.row }
    },
    methods: {
        async getType() {
            let res = await supplierLabel({ type: 9 })
            if (res.code === 200) {
                this.typeArr = res.data
            }
        },
        fileArrysData: function(list) {
            this.formData.fileInfo = [...list]
        },

        getCertificate: function() {
            supplierLabel({
                type: 10
            }).then(res => {
                if (res.code === 200) {
                    this.certificateArr = res.data
                }
            })
        },
        openPerson: function() {
            if (!this.formData.branchComId) {
                this.$message.error('选择考察人员之前请先选择考察单位')
                return
            }
            this.$refs.personList.open()
        },
        openOrg: function() {
            this.$refs.orgList.open()
        },
        getOrg: function(row) {
            this.formData.branchComName = row.name
            this.formData.branchComId = row.id
        },
        getPerson: function(row) {
        },
        temporaryStorage(val) {
            this.$refs.ruleForm.validate(async (valid, object) => {
                if (valid) {
                    if (this.state !== 3) {
                        this.$console(this.formData)
                        // let commitData = this.$clone(this.formData)
                        // delete commitData.memberList
                        let res = await contentEidt(this.formData)
                        if (res.code === 200) {
                            this.$message.success('保存成功')
                            this.isSubmit = true
                            this.$bus.$emit('update')
                        }
                    }
                } else {
                  this.$message.warning("请填写完所有必填项信息")
                    return false
                }
            })
        }
    }
}
</script>
